/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package upeu.edu.dao;

import java.util.List;
import java.util.Locale;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import upeu.edu.pe.model.SauEstandar;

/**
 *
 * @author DANIEL
 */
@Repository("EstandarDao")
public class EstandarDaoImplements implements EstandarDao {

    @Autowired
    public SessionFactory sesionFactory;

    @Override
    public List<SauEstandar> listaEstandar() {
        return sesionFactory.getCurrentSession().createCriteria(SauEstandar.class).list();
    }
    @Override
    public void insertarEstandar(SauEstandar estandar ){
        System.out.println(estandar.getNombre());        
          Session session =sesionFactory.openSession();
          session.beginTransaction().begin();
          //  session.persist(estandar);
            session.save(estandar);
          session.beginTransaction().commit();          
    }
    
    @Override
    public void eliminarEstandar(String idEstandar){
        sesionFactory.getCurrentSession().createQuery("delete SauEstandar per where per.idEstandar=?")
                .setString(0, idEstandar).executeUpdate();
        
    }
    
    @Override
    public SauEstandar buscarIdEstandar(String idEstandar){
        return (SauEstandar)sesionFactory.getCurrentSession().get(SauEstandar.class, idEstandar);
    }
    
    @Override
    public void actualizarEstandar(SauEstandar estandar){
        Session sesion=sesionFactory.openSession();
        System.out.println(""+estandar.getFecha());
        try {
            sesion.beginTransaction().begin();
            sesion.update(estandar);
            sesion.getTransaction().commit();
            
        } catch (Exception e) {
        }
    }
    
}
